package com.haitaoit.chengquan.business.data;

import android.content.Context;
import android.os.Handler;

import com.google.gson.Gson;
import com.haitaoit.chengquan.business.http.QLResponseCall;
import com.haitaoit.chengquan.business.http.bean.ParamObj;
import com.haitaoit.chengquan.business.request.PublicPostReq;
import com.haitaoit.chengquan.business.request.PublicServiceReq;
import com.haitaoit.chengquan.module.center.model.MyAddressModel;
import com.haitaoit.chengquan.utils.AppLog;
import com.haitaoit.chengquan.utils.Constant;

import java.util.List;

/**
 * ClassName:发布服务
 * author: Cocoa
 * date: 2016/9/28.
 */

public class PublicServiceHttp extends BaseHttp {
    private Handler handler;
    private int            what;
    private String url= Constant.add_service;
    private List<ParamObj> paramObjs;
    private PublicServiceReq publicServiceReq;

    public PublicServiceHttp(Context context, Handler handler, List<ParamObj> paramObjs, PublicServiceReq publicServiceReq, int what) {
        this.context = context;
        this.handler = handler;
        this.publicServiceReq = publicServiceReq;
        this.what = what;
        this.paramObjs = paramObjs;
        start();
    }

    private void start() {

        AppLog.D("url:" + url+getParamObjsToString(paramObjs));

        String jsonStr=new Gson().toJson(publicServiceReq);
        AppLog.D("url_json:" + jsonStr);
        getHttp().post(url+getParamObjsToString(paramObjs), jsonStr,new QLResponseCall() {
            @Override
            public void onStart() {
                    onStartHandler(handler);
            }

            @Override
            public void onFailure(String arg0, int error) {
                AppLog.D("onFailure:" + error);
                AppLog.D("onFailure:" + arg0);
                onFailureHandler(context, handler, arg0, error);
            }

            @Override
            public void onSuccess(String result) {
                AppLog.D("result:" + result);
                onSuccessHandler(context, handler, result);
            }
        });
    }



    @Override
    void getData(Handler handler, BaseDataResp responseObj) {
        sendHandler(handler, new Gson().fromJson(responseObj.getResponse(), MyAddressModel.class), what);
//        List<AttacheListResp> attacheListResps = new Gson().fromJson(responseObj.getSuccess(), new TypeToken<List<AttacheListResp>>() {
//        }.getType());
    }
}
